

clear all
cap log close

*Graph style
sysdir set PERSONAL "W:\ado"
set scheme kailaScheme


global dummies =  "dpl_5 dpl_4 dpl_3 dpl_2 dpl_0 dpl1 dpl2 dpl3 dpl4 dpl5"
global fe_full = "baseid time year" 
global cluster = "sykstun"

	
use "${dataout}turnover_allyears_violentfirms", clear



sort match_id1 year_event time sykstun
bys match_id1 year_event time: ereplace mm=max(mm)
bys match_id1 year_event time: ereplace mf=max(mf)
bys match_id1 year_event time: ereplace new_wp_crime=max(new_wp_crime)



bysort match_id1 year_event time: keep if _N==2 





sort sykstun year_event time
replace switch=0 if switch==. 
bys sykstun year_event: gen share_switch3=-switch/employee
bys sykstun year_event: gen share_fswitch3=-switch_female/employee
bys sykstun year_event: gen share_mswitch3=-switch_male/employee


sum share_fswitch3,d
local top1= r(p99)
replace  share_fswitch3=`top1' if share_fswitch3>`top1'  

bys sykstun year_event: gen share_newhire3=newhire/employee
bys sykstun year_event: gen share_fnewhire3=female_newhire/employee
bys sykstun year_event: gen share_mnewhire3=male_newhire/employee


gen baseyr=year_event
assert time >= -5 & time <= 5 
gen treat= wp_crime==1




*Time displacement dummies
g dpl_5=time==-5 & treat==1
g dpl_4=time==-4 & treat==1
g dpl_3=time==-3 & treat==1
g dpl_2=time==-2 & treat==1
g dpl_1=time==-1 & treat==1
g dpl_0=time==0 & treat==1
gen dpl1=time==1 & treat==1
gen dpl2=time==2 & treat==1
gen dpl3=time==3 & treat==1
gen dpl4=time==4 & treat==1
gen dpl5=time==5 & treat==1

gen treatPost= treat==1 & time>0



* Generate treatment wave indentifier for each individual
egen baseid=group(sykstun)

lab var treatPost "Treatment"


*preserve 
keep if new_wp_crime==1
* Main regression will all fixed effects
reghdfe share_female treatPost if mf==1, absorb($fe_full)  cluster($cluster)
est sto fshare_mf
reghdfe share_fnewhire3 treatPost if mf==1, absorb($fe_full)  cluster($cluster)
est sto fhire_mf
reghdfe share_fswitch3 treatPost if mf==1, absorb($fe_full)  cluster($cluster)
est sto fturn_mf	
	



coefplot fshare_mf fhire_mf fturn_mf, keep(treatPost) ///
	vertical yline(0) ytitle("Coefficient - Female Share")  ///
	legend(order(2 "Employees" 4 "Hires" 6 "Turnover") rows(1)) ///
	name(victim, replace) ///
	recast(bar) barwidth(0.2) fcolor(*0.8) ciopts(recast(rcap)) citop ///
	yscale(r(-0.04 0.04)) ylabel(-0.04(0.02)0.04) 
	graph export "${results}\firm_female_turnover_hire_DiD_mf.pdf", replace
	
	
preserve 
set scheme s1mono
	coefplot fshare_mf fhire_mf fturn_mf, keep(treatPost) ///
	vertical yline(0) ytitle("Coefficient - Female Share")  ///
	legend(order(2 "Employees" 4 "Hires" 6 "Turnover") rows(1)) ///
	name(victim, replace) ///
	recast(bar) barwidth(0.2) fcolor(*0.8) ciopts(recast(rcap)) citop ///
	yscale(r(-0.04 0.04)) ylabel(-0.04(0.02)0.04) 
	graph export "${results}\firm_female_turnover_hire_DiD_mf_bw.pdf", replace
    graph export "${results}\firm_female_turnover_hire_DiD_mf.eps", replace
restore 